﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BreakOutBattles.IO.Net;

namespace BreakOutBattles.Game
{
    public static class JoinManager
    {
        public static Player HostPlayer { get; set; }
        public static Player SecondaryPlayer { get; set; }
        public static GameNetClient Client { get; set; }
        public static MatchConfiguration HostConfiguration { get; set; }


        public static void HostConfigurationReceived(object sender, MatchConfiguration matchConfiguration)
        {
            HostConfiguration = matchConfiguration;
            HostPlayer.Name = matchConfiguration.LevelName;
            HostPlayer.Lifes = matchConfiguration.LifesPerRound;
            HostPlayer.IsRemotePlayer = true;
            HostPlayer.PlayerIndex = 0;

            SecondaryPlayer.Lifes = matchConfiguration.LifesPerRound;
            GameState.CurrentState = GameStates.GAME_RUNNING;
        }

        public static void SecondaryConfigurationReceived(object sender, JoinClientConfig configuration)
        {
            SecondaryPlayer.Name = configuration.PlayerName;
            SecondaryPlayer.Lifes = HostConfiguration.LifesPerRound;
            SecondaryPlayer.IsRemotePlayer = true;
            SecondaryPlayer.PlayerIndex = 1;

            //When the secondary player has sent the infomation, the host configuration need to be sent.
            Client.SendHostConfigMessage(HostConfiguration);
            GameState.CurrentState = GameStates.GAME_RUNNING;
        }
    }
}
